package second.hash;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

public class Solution04 {
    public boolean isHappy(int n) {
        HashMap<Integer, Objects> map = new HashMap<>();
        int sum = 0;
        while (n != 0 && n != 1) {
            if (map.containsKey(n)) return false;
            map.put(n, null);
            while (n != 0) {
                int tmp = n % 10;
                sum += tmp * tmp;
                n /= 10;
            }
            n = sum;
            sum = 0;
        }
        return true;
    }
}
